import {
	preOrderApi,
	continueState
} from '@/api/order.js';
import util from 'utils/util'
	const app = getApp();
/**
 * 去商品详情
 */
export function goShopDetail(item, uid) {
	return new Promise(resolve => {
		if (item.activityH5 && item.activityH5.type === "1") {
			uni.navigateTo({
				url: `/pages/activity/goods_seckill_details/index?id=${item.activityH5.id}`
			})
		} else if (item.activityH5 && item.activityH5.type === "2") {
			uni.navigateTo({
				url: `/pages/activity/goods_bargain_details/index?id=${item.activityH5.id}&startBargainUid=${uid}`
			})
		} else if (item.activityH5 && item.activityH5.type === "3") {
			uni.navigateTo({
				url: `/pages/activity/goods_combination_details/index?id=${item.activityH5.id}`
			})
		} else {
			resolve(item);
		}
	});
}

/**
 * 活动商品、普通商品、购物车、再次购买预下单
 */
export function getPreOrder(preOrderType, orderDetails) {
	return new Promise((resolve, reject) => {
		preOrderApi({
			"preOrderType": preOrderType,
			"orderDetails": orderDetails
		}).then(res => {
			console.log(res,'res');
			let that = this;
			// if(res.data.nowMoney == 'false' && res.data.nowMoney !== null) {
			// 		console.log('res',res.data);
			// 	 uni.showModal({
			// 	 	title:"提示",
			// 		content:res.data.isReservation,
			// 		success: function(res) {
			// 			if (res.confirm) {
			// 				return
			// 			}
			// 		}
			// 	 })
							
			// }
		uni.navigateTo({
			url: '/pages/users/order_confirm/index?preOrderNo=' + res.data.preOrderNo
		});
			// if(res.data.isReservation !==null && res.data.isReservation == 'false'){
			// 	uni.showModal({
			// 		title:"提示",
			// 		content:res.data.isReservation,
			// 		success: function(res) {
			// 					if (res.confirm) {
			// 						continueState(orderDetails[seckillId])
			// 							.then(res => {
			// 								console.log(res,'成功扣除费用');
											
											
			// 							})
			// 							.catch(err => {
			// 								console.log(err);
			// 							});
			// 					} else if (res.cancel) {
			// 						console.log('用户点击取消');
			// 					}
			// 				}
			// 	})
			// }
			
		}).catch(err => {
			return util.Tips({
				title: err
			});
		})
	});
}
